﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using HHL_Acc.HHL_DaoAcc.DataObject;
using HHL_Acc.HHL_EntityAcc;
using HHL_DaoAcc.DataObject;
namespace HHL_Acc.HHL_BussAcc.DataObject
{
    class SmiTicketCompBus
    {
        private SmiTicketCompDao smiTicketCompDao;

        public SmiTicketCompBus()
        {
            smiTicketCompDao = new SmiTicketCompDao();
        }
        public DataTable GetAllSmiTicketComp()
        {
            return smiTicketCompDao.GetAllSmiTicketComp();
        }
        //
        public DataTable GetListWithTicketcode(string str)
        {
            return smiTicketCompDao.GetListWithTicketcode(str);
        }
        public DataTable GetListLikeString(string str)
        {
            return smiTicketCompDao.GetListWithTicketcode(str);
        }
        // kiểm tra vé có nằm trong kho hay không
        public bool isExistTicketComp(int sriFrom, int sriEnd, string ticket,string symbol)
        {
            int from, end;
            int qty;
            string sym;
            DataTable list = new DataTable();
            list = smiTicketCompDao.GetListWithTicketcode(ticket);
            if (list.Rows.Count > 0)
            {
                foreach (DataRow row in list.Rows)
                {
                    sym = row["SerialFrom"].ToString().Substring(0, 7);
                    if (sym == symbol)
                    {
                        qty = int.Parse(row["Qty"].ToString());
                        from = int.Parse(row["SerialFrom"].ToString().Substring(9,6));
                        end = from + qty;
                        if ((sriFrom >= from && sriFrom <= end) && (sriEnd >= from && sriEnd <= end))
                        {
                            return true;
                        }
                    }
                }
            }
            else {
                return false;
            }
            return false;
        }
    }
}
